|
1
|
|
|
import { HttpProxyAgent, HttpsProxyAgent } from 'hpagent'; |
|
2
|
|
|
|
|
3
|
|
|
export interface SitemapperSiteData { |
|
4
|
|
|
loc: string; |
|
5
|
|
|
lastmod?: string; |
|
6
|
|
|
priority?: string; |
|
7
|
|
|
changefreq?: string; |
|
8
|
|
|
[key: string]: any; |
|
9
|
|
|
} |
|
10
|
|
|
|
|
11
|
|
|
export interface SitemapperResponse { |
|
12
|
|
|
url: string; |
|
13
|
|
|
sites: string[] | SitemapperSiteData[]; |
|
14
|
|
|
errors: SitemapperErrorData[]; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
export type SitemapperResponseSite = { [name in SitemapperField]?: string }; |
|
18
|
|
|
|
|
19
|
|
|
export interface SitemapperErrorData { |
|
20
|
|
|
type: string; |
|
21
|
|
|
url: string; |
|
22
|
|
|
retries: number; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
export type SitemapperField = |
|
26
|
|
|
| 'loc' |
|
27
|
|
|
| 'sitemap' |
|
28
|
|
|
| 'lastmod' |
|
29
|
|
|
| 'changefreq' |
|
30
|
|
|
| 'priority' |
|
31
|
|
|
| 'image:loc' |
|
32
|
|
|
| 'image:title' |
|
33
|
|
|
| 'image:caption' |
|
34
|
|
|
| 'video:title' |
|
35
|
|
|
| 'video:description' |
|
36
|
|
|
| 'video:thumbnail_loc'; |
|
37
|
|
|
|
|
38
|
|
|
export type SitemapperFields = { [name in SitemapperField]?: boolean }; |
|
39
|
|
|
|
|
40
|
|
|
export interface SitemapperOptions { |
|
41
|
|
|
concurrency?: number; |
|
42
|
|
|
debug?: boolean; |
|
43
|
|
|
lastmod?: number; |
|
44
|
|
|
rejectUnauthorized?: boolean; |
|
45
|
|
|
requestHeaders?: { [name: string]: string }; |
|
46
|
|
|
retries?: number; |
|
47
|
|
|
timeout?: number; |
|
48
|
|
|
url?: string; |
|
49
|
|
|
fields?: SitemapperFields; |
|
50
|
|
|
proxyAgent?: HttpProxyAgent | HttpsProxyAgent; |
|
51
|
|
|
exclusions?: RegExp[]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
declare class Sitemapper { |
|
55
|
|
|
timeout: number; |
|
56
|
|
|
url: string; |
|
57
|
|
|
debug: boolean; |
|
58
|
|
|
lastmod: number; |
|
59
|
|
|
fields?: { [name: string]: boolean }; |
|
60
|
|
|
requestHeaders?: { [name: string]: string }; |
|
61
|
|
|
concurrency?: number; |
|
62
|
|
|
retries?: number; |
|
63
|
|
|
rejectUnauthorized?: boolean; |
|
64
|
|
|
exclusions?: RegExp[]; |
|
65
|
|
|
proxyAgent?: any; |
|
66
|
|
|
timeoutTable: { [url: string]: NodeJS.Timeout }; |
|
67
|
|
|
|
|
68
|
|
|
constructor(options?: SitemapperOptions); |
|
69
|
|
|
|
|
70
|
|
|
private initializeTimeout(url: string, requester: any): void; |
|
71
|
|
|
private crawl(url: string, retryIndex?: number): Promise<any>; |
|
72
|
|
|
private parse(url: string): Promise<any>; |
|
73
|
|
|
isExcluded(url: string): boolean; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Gets the sites from a sitemap.xml with a given URL |
|
77
|
|
|
* |
|
78
|
|
|
* @param url URL to the sitemap.xml file |
|
79
|
|
|
*/ |
|
80
|
|
|
fetch( |
|
81
|
|
|
this: Sitemapper & { fields: object }, |
|
82
|
|
|
url?: string |
|
83
|
|
|
): Promise< |
|
84
|
|
|
Omit<SitemapperResponse, 'sites'> & { sites: SitemapperSiteData[] } |
|
85
|
|
|
>; |
|
86
|
|
|
fetch( |
|
87
|
|
|
url?: string |
|
88
|
|
|
): Promise<Omit<SitemapperResponse, 'sites'> & { sites: string[] }>; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @deprecated Use fetch() instead. |
|
92
|
|
|
*/ |
|
93
|
|
|
getSites( |
|
94
|
|
|
url: string | undefined, |
|
95
|
|
|
callback: (err: Error | null, sites: string[]) => void |
|
96
|
|
|
): Promise<void>; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
export default Sitemapper; |
|
100
|
|
|
|